﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Handrise.BasicModal.Serialization;

namespace Handrise.CDCable.Business
{
    /// <summary>
    /// 关联文件处理服务
    /// </summary>
    public class LinkFileService
    {
        private ServerExchange serverExchange = new ServerExchange();
        
        public bool UploadFile(string userName, byte[] fileInfo, byte[] fileBuffer)
        {
            //获取文件信息
            CompactFormatterPlus cfp = new CompactFormatterPlus();
            LinkFile linkFile = (LinkFile)cfp.Deserialize(fileInfo);

            //把文件流转换成Base64编码的字符串
            string fileByte = "" ;
            try
            {
                fileByte = CommonFunction.toBase64(fileBuffer);

            }
            catch (Exception e)
            {

            }

            //通过主站服务上传文件
            string receiveData = serverExchange.UploadFile(userName,linkFile.LinkID, userName, fileByte, linkFile.Title, linkFile.Type);

            return CommonFunction.ReturnDataIsOk(receiveData); ;

        }
    }
}
